//
//  IOS_IDFA_Plugin.m
//  
//
//  Created by wyht－ios－dev on 16/6/2.
//
//

#import <UIKit/UIKit.h>
#import "SSDKEventManager.h"
#import "SuperSDKPluginTools/SSDKPluginJsonUtil.h"
#import "libSuperSDK.h"

#if defined(_cplusplus)
extern "C"{
#endif
    
    const char * ios_plugin_manager_call (char* funName,char* args)
    {
        char* res=NULL;
        NSString *funNameStr=@"";
        NSString *argsStr=@"";
        NSString *result = @"";
        if(funName)
            funNameStr = [NSString stringWithUTF8String: funName];
        if(args)
            argsStr=[NSString stringWithUTF8String:args];
//        if([funNameStr isEqualToString:@"ios_deviceid_plugin"]) {
//            result=[IOS_Plugin_DeviceID getDeviceID];
//        }
//        if([funNameStr isEqualToString:@"ios_idfa_plugin"]) {
//            result=[IOS_Plugin_IDFA getIDFA];
//        }
//        if([funNameStr isEqualToString:@"ios_jpush_plugin"]) {
//            [IOS_Plugin_JPUSH setAlias:argsStr];
//        }
//        if([funNameStr isEqualToString:@"ios_submit_deviceinfo_plugin"]) {
//            [IOS_Plugin_SubmitInfo submitDeviceInfo];
//        }
//        if([funNameStr isEqualToString:@"ios_call_unity_init"]) {
//            [IOS_Plugin_Call_Unity ios_call_unity_init:argsStr];
//        }
//        if([funNameStr isEqualToString:@"ios_share_plugin"]) {
//        }
//        if([funNameStr isEqualToString:@"ios_facebook_invite_plugin"]) {
//        }
        if([funNameStr isEqualToString:@"ios_wechat_share"]) {
            //调用地理位置
//            [SSDKEventManager postNotificationName:@"GetLocation_getPlayerLocation" object:nil];
            
            //调用分享插件
//            NSDictionary *data = @{@"filePath":argsStr,@"UNITY_OBJ":@"Main Camera", @"UNITY_PLUGIN_CALLBACK":@"ScreenShotCallback"};
//            [SSDKEventManager postNotificationName:@"plugin_event_wechat_share" object:data];
            
            //调用调查问卷插件
            [SSDKEventManager postNotificationName:@"plugin_event_survey_show" object:argsStr];
            
            //打开扫码
//            [SSDKEventManager postNotificationName:@"plugin_event_qrscan" object:@{@"UNITY_OBJ":@"Main Camera", @"UNITY_PLUGIN_CALLBACK":@"QrCodeCallback"}];
            
            //生成二维码
//            [SSDKEventManager postNotificationName:@"plugin_event_qrgen" object:@{@"UNITY_OBJ":@"Main Camera", @"UNITY_PLUGIN_CALLBACK":@"CreateQrCodeCallback", @"QRCodeUrl":@"www.baidu.com"}];
            
            //选择照片
//            [SSDKEventManager postNotificationName:@"plugin_event_photopicker" object:@{@"UNITY_OBJ":@"Main Camera", @"UNITY_PLUGIN_CALLBACK":@"getPhotoCallback"}];
            
            //获取设备信息
//            [SSDKEventManager postNotificationName:@"plugin_event_deviceinfo"
//                                            object:@{@"UNITY_OBJ":@"Main Camera", @"UNITY_PLUGIN_CALLBACK":@"CreateQrCodeCallback", @"deviceKey":@"all"}];
            
            //小精灵
//            JinglingInterface *jingling = [[JinglingInterface alloc] init];
//            [jingling setListener:[[Plugin_JinglingConnector alloc] init]];
//            [jingling startKnowledge:@{@"config_url":@"http://119.29.237.134/v0.1/hhw/conf/layout.min.json",
//                                       @"player_portrait":@"http://file01.16sucai.com/d/file/2013/0616/20130616021845926.png",
//                                       @"system_portrait":@"http://file01.16sucai.com/d/file/2013/0616/20130616021845320.png",
//                                       @"app":@"hhw",
//                                       @"level":@12,
//                                       @"vip":@0,
//                                       @"uid":@"20996000001",
//                                       @"app_channel":@"",
//                                       @"sch":@"弓箭手",
//                                       @"iz":@"蒲家村"}];
            
            
        }
//        if([funNameStr isEqualToString:@"getDeviceInfo"]) {
//            result=[IOS_Plugin_DeviceInfo getDeviceInfo:argsStr];
//        }
        
        res = (char*)malloc(strlen([result UTF8String]) + 1);
        strcpy(res, [result UTF8String]);
        return res;
    }
    
    const char * ios_plugin_manager_call_with_class (char* className,char* funName,char* args) {
        char* res=NULL;
        NSString *classNameStr=@"";
        NSString *funNameStr=@"";
        NSString *argsStr=@"";
        NSString *result = @"";
        if(className)
            classNameStr=[NSString stringWithUTF8String:className];
        if(funName)
            funNameStr = [NSString stringWithUTF8String: funName];
        if(args)
            argsStr=[NSString stringWithUTF8String:args];
        
        //获取地理位置信息
        if([classNameStr isEqualToString:@"GetLocation"]) {
            if([funNameStr isEqualToString:@"getLocation"]) {
                [SSDKEventManager postNotificationName:@"GetLocation_getPlayerLocation" object:[SSDKPluginJsonUtil toObjectWithJson:argsStr]];
            }
        }
        //获取相册照片或拍照
        if([classNameStr isEqualToString:@"PhotoPick"]) {
            if([funNameStr isEqualToString:@"get"]) {
                [SSDKEventManager postNotificationName:@"plugin_event_photopicker"
                                                object:[SSDKPluginJsonUtil toObjectWithJson:argsStr]];
            }
        }
        //分享
        if([classNameStr isEqualToString:@"SuperSDKScreenShot"]) {
            //获取二维码
            if([funNameStr isEqualToString:@"qrCode"]) {
                [SSDKEventManager postNotificationName:@"plugin_event_wechat_share_url"
                                                object:[SSDKPluginJsonUtil toObjectWithJson:argsStr]];
            }
            //分享接口
            if([funNameStr isEqualToString:@"screenShotShare"]) {
                [SSDKEventManager postNotificationName:@"plugin_event_wechat_share" object:[SSDKPluginJsonUtil toObjectWithJson:argsStr]];
            }
        }
        //二维码
        if([classNameStr isEqualToString:@"QRCode"]) {
            //生成二维码插件
            if([funNameStr isEqualToString:@"Create"]) {
                [SSDKEventManager postNotificationName:@"plugin_event_qrgen"
                                                object:[SSDKPluginJsonUtil toObjectWithJson:argsStr]];
            }
        }
        //获取设备信息(V1版，同步返回)
        if([classNameStr isEqualToString:@"AndDeviceInfo"]) {
            if([funNameStr isEqualToString:@"getDeviceInfo"]) {
                // 反射调用
                Class c = NSClassFromString(@"Plugin_DeviceInfo");
                SEL selector = NSSelectorFromString(@"getDeviceInfo:");
                IMP imp = [c methodForSelector:selector];
                NSString * (*func)(id, SEL, NSString *) = (void *)imp;
                result = func(c, selector, argsStr);
            }
        }
        //获取设备信息(V2版，异步回调)
        if([classNameStr isEqualToString:@"DeviceInfo"]) {
            if([funNameStr isEqualToString:@"get"]) {
                [SSDKEventManager postNotificationName:@"plugin_event_deviceinfo"
                                                object:[SSDKPluginJsonUtil toObjectWithJson:argsStr]];
            }
        }
        
        //屏幕亮度插件(同步执行)
        if([classNameStr isEqualToString:@"ScreenBrightness"]) {
            if([funNameStr isEqualToString:@"getBrightness"]) {
                // 反射调用
                Class c = NSClassFromString(@"Plugin_LightConfig");
                SEL selector = NSSelectorFromString(@"getDeviceInfo:");
                IMP imp = [c methodForSelector:selector];
                NSString * (*func)(id, SEL, NSString *) = (void *)imp;
                result = func(c, selector, argsStr);
            }
        }
        
        res = (char*)malloc(strlen([result UTF8String]) + 1);
        strcpy(res, [result UTF8String]);
        return res;
    }
    
#if defined(_cplusplus)
}
#endif

